-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat deser class by schema collection userfriendlyapi #377
Feat deser class by schema collection userfriendlyapi #377
Conversation
fcc2b24
to
c0ab23d
Compare
AUTO_RECONSCTRUCT_BY_JSON_SCHEME.md
Outdated
is_inited: "boolean", | ||
records: {map: { key: 'string', value: 'string' }}, | ||
truck: Truck, | ||
messages: {array: {value: 'string'}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this messages: "array"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove it since no reconstruct is needed. I will update it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
@@ -28,7 +28,8 @@ class Truck { | |||
static schema = { | |||
name: "string", | |||
speed: "number", | |||
loads: {collection: {reconstructor: UnorderedMap.reconstruct, value: 'string'}} | |||
// loads: {collection: {reconstructor: UnorderedMap.reconstruct, value: 'string'}} | |||
loads: {class: UnorderedMap } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice this case still works. I think this is worth mention as an example in readme, as one case in:
export class StatusDeserializeClass {
static schema = {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I have a few minor concerns on the documentation above, other than that this api is quite easy to use and well implemented!
fixed the documentation on the doc |
@fospring @ailisp I think it would be much clearer if we follow this idea: https://github.com/nameskyteam/borsher Basically, it would look like this: import {Schema} from 'near-sdk-js'
class Car {
schema = { brand: Schema.string, velocity: Schema.number }
}
class Contract {
schema = {
field1: Schema.string,
field2: Schema.HashMap(Schema.string, Schema.number),
field3: Schema.Array(Schema.bigInt),
field4: Schema.Class(Car)
field5: Schema.Option(number)
}
} This has several advantages:
We could even just grab the https://github.com/nameskyteam/borsher and import it directly into here. |
great suggestion! I will update it |
@gagdiez great suggestion! If it's adding a lot work, let's keep the behavior for:
|
It looks a little difficult, I will try to resolve it in a new MR |
@fospring sounds good to me, ping me and I'll see to help as well |
Great! |
c3830f2
to
ed0bda2
Compare
Pre-flight checklist
Motivation
add suguar to decode class, create more friendly API, resolve comment of: #370 (comment)
Test Plan
Related issues/PRs